// JavaScript Document
function validateEmail(email) {
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if (!re_mail.test(email.value)) {
		return false;
	}
	return true;
}
//--
var value = true;
function check_all(object) {
	var f = object;
	var obj = f.elements["checked_delete[]"];
	if (obj) {
		if (obj.length) 
			for (i=0;i<obj.length;i++)
				obj[i].checked = value;
		else
			obj.checked = value;
		value = value==false?true:false;
	}
}
function edit(object){
	location.href = object;	
}
function add(object){
	location.href = object;	
}
function SEND(type, object){
	var f = object;
	f.type.value=type;	
	f.submit();
	return true;
}
function update(type, object){
	var f = object;
	f.type.value=type;	
	f.submit();
	return true;
}
function del(type, object) {
	var f = object;
	var obj = f.elements["checked_delete[]"];
	if (obj) {
		var del = false;
		if (obj.length) {
			for (i=0;i<obj.length;i++)
				if (obj[i].checked==true) del=true;
		} else {
			if (obj.checked==true) { del=true; }
		}
		if (del==false) {
			alert("Please check to delete?");
		} else {
		   if(confirm('Are you sure you want to delete?')==true){
				f.type.value = type;
				f.submit();
		   }	
		}
	}
}
// SUSPEND
function check_all_suspend(object) {
	var f = object;
	var obj = f.elements["checked_suspend[]"];
	if (obj) {
		if (obj.length) 
			for (i=0;i<obj.length;i++)
				obj[i].checked = value;
		else
			obj.checked = value;
		value = value==false?true:false;
	}
}
function suspend(type, object) {
	var f = object;
	var obj = f.elements["checked_suspend[]"];
	if (obj) {
		var suspend = false;
		if (obj.length) {
			for (i=0;i<obj.length;i++)
				if (obj[i].checked==true) suspend=true;
		} else {
			if (obj.checked==true) { suspend=true; }
		}
		if (suspend==false) {
			alert("Please check to suspend?");
		} else {
		   if(confirm('Are you sure you want to suspend?')==true){
				f.type.value = type;
				f.submit();
		   }	
		}
	}
}
// UPGRADE
function check_all_upgrade(object) {
	var f = object;
	var obj = f.elements["checked_upgrade[]"];
	if (obj) {
		if (obj.length) 
			for (i=0;i<obj.length;i++)
				obj[i].checked = value;
		else
			obj.checked = value;
		value = value==false?true:false;
	}
}
function upgrade(type, object) {
	var f = object;
	var obj = f.elements["checked_upgrade[]"];
	if (obj) {
		var upgrade = false;
		if (obj.length) {
			for (i=0;i<obj.length;i++)
				if (obj[i].checked==true) upgrade=true;
		} else {
			if (obj.checked==true) { upgrade=true; }
		}
		if (upgrade==false) {
			alert("Please check to upgrade?");
		} else {
		   if(confirm('Are you sure you want to upgrade?')==true){
				f.type.value = type;
				f.submit();
		   }	
		}
	}
}
//-- Save menu category
function doSaveMenuCate(){
	var frm = document.frmAddCate;
	if(frm.cate_name.value == ''){
		alert("Please insert category name!");
		frm.cate_name.focus();
		return;
	}
	if(frm.s_cate_id.value > 0){
		if(frm.cate_mod.value == ''){
			alert("Please insert category mod!");
			frm.cate_mod.focus();
			return;
		}
		if(frm.cate_act.value == ''){
			alert("Please insert category act!");
			frm.cate_act.focus();
			return;
		}
	}
	frm.submit();
}
//-- Save left Panel
function doSaveleftpanel(){
	var frm = document.frmAddleftPanel;
	if(frm.cate_name.value == ''){
		alert("Please insert category name!");
		frm.cate_name.focus();
		return;
	}
	if(frm.s_cate_id.value > 0){
		if(frm.cate_act.value == ''){
			alert("Please insert category act!");
			frm.cate_act.focus();
			return;
		}
	}
	frm.submit();
}
// save menu sub left
function doSavesubleft(){
	var frm = document.frmaddsubleft;
	if(frm.cate_name.value == ''){
		alert("Please insert category name!");
		frm.cate_name.focus();
		return;
	}
	if(frm.cate_mod.value == ''){
		alert("Please insert category mod!");
		frm.cate_mod.focus();
		return;
	}
	if(frm.cate_act.value == ''){
		alert("Please insert category act!");
		frm.cate_act.focus();
		return;
	}
	frm.submit();
}

//end
//-- Save global config
function doSaveGlobalConfig(){
	var frm = document.frmGlobalConfig;
	frm.submit();
}

// save left_content
function doSaveleft_content(){
	var frm = document.frmAddleft_content;
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return;
	}
	
	frm.submit();
}


//-- Save static page
function doSaveStaticPage(){
	var frm = document.frmStaticPage;
	if(frm.title.value == ''){
		alert("Please insert the page title!");
		frm.title.focus();
		return;
	}
	frm.submit();
}
// about
//-- Save static page
function doSaveabout(){
	var frm = document.frmabout;
	if(frm.name.value == ''){
		alert("Please insert the page name!");
		frm.name.focus();
		return;
	}
	frm.submit();
}


//-- Save press_centre
function doSavepress_centre(){
	var frm = document.frmAddpress_centre;
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return;
	}
	
	frm.submit();
}
//-- Save branch
function doSavepages(){
	var frm = document.frmAddPages;
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return;
	}
	frm.submit();
}
// staff
function doSavestaff(){
	var frm = document.frmAddstaff;
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return;
	}
	if (frm.email.value.indexOf('@',0) == -1 || frm.email.value.indexOf('.',0) == -1){
		alert(" Invalid email address supplied. Please re-check your email address!") ;
		frm.email.focus() ;
		return ;
	}
	frm.submit();
}
// newsletter
function doSavenewsletter(){
	var frm = document.frmAddnewsletter;
	if(frm.subject.value == ''){
		alert("Please insert the subject!");
		frm.subject.focus();
		return;
	}
	frm.submit();
}
//customer 
//-- Do login admin
function doemail_to(){
	var frm = document.frmAddnewsletter;
	if(frm.subject.value == ''){
		alert("Please insert the subject!");
		frm.subject.focus();
		return;
	}
	frm.submit();
}

function doSavecustomer(){
	var frm = document.frmAddcustomer;
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return;
	}
	frm.submit();
}
//testimonials
function doSavetestimonials(){
	var frm = document.frmAddtestimonials;
	if(frm.name.value == ''){
		alert("Please insert the testimonials name!");
		frm.headline.focus();
		return;
	}
	frm.submit();
}


//used equipment
function doSaveused_equip(){
	var frm = document.frmAddused_equip;
	if(frm.headline.value == ''){
		alert("Please insert the used equipment name!");
		frm.headline.focus();
		return;
	}
	frm.submit();
}


// Save news
function doSavenews(){
	var frm = document.frmAddnews;
	if(frm.title.value == ''){
		alert("Please insert the title!");
		frm.title.focus();
		return;
	}
	frm.submit();
}
//save supplier
function doSavesupplier(){
	var frm = document.frmAddnews;
	if(frm.code.value == ''){
		alert("Please insert the code!");
		frm.code.focus();
		return false;
	}
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return false;
	}
	if(frm.email.value == ''){
		alert("Please insert the email!");
		frm.email.focus();
		return false;
	}else{
		var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
		if (!re_mail.test(frm.email.value)) {
			return false;
		}
	}
	frm.submit();
}
//-- check Categery
function doCategory(){
	var frm = document.frmAddnews;
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return;
	}
	frm.submit();
}
//--check Product
function doProduct(){
	var frm = document.frmAddnews_product;
	if(frm.product_name.value == ''){
		alert("Please insert the Product Name!");
		frm.name.focus();
		return;
	}
	frm.submit();
}
//-- check Categery
function doBrand(){
	var frm = document.frmAddnews;
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return;
	}
	frm.submit();
}
//-- check mail
function validateEmail(email){
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if (!re_mail.test(email.value)) {
		return false;
	}
	return true;
}
//-- Save 
function doSavebranch(){
	var frm = document.frmAddbranch;
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return;
	}
	if(frm.address.value==''){
			alert("Please insert address!");
			frm.address.focus();
			return;
	}
	if(validateEmail(frm.email)){
		frm.submit();
	}
	else{
		alert('Invalid email address supplied. Please re-check your email address.');
	}

}
//-- Save testimonials
function doSavetestimonials_cate(){
	var frm = document.frmtestimo;
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return;
	}
	frm.submit();
}

//-- Save used_equip
function doSaveused_equip_cate(){
	var frm = document.frmused_equip;
	if(frm.name.value == ''){
		alert("Please insert the name!");
		frm.name.focus();
		return;
	}
	frm.submit();
}

//-- Save static page

function doSaveadmin(){
	var frm = document.frmadmin;
	if(frm.admin_name.value == ''){
		alert("Please insert the  Name!");
		frm.admin_name.focus();
		return;
	}
	if(frm.admin_username.value == ''){
		alert("Please insert the Usename!");
		frm.admin_username.focus();
		return;
	}
	if(frm.admin_password.value != ''){
		if(frm.admin_password.value.length < 6){
			alert("Password must have at least 6 characters!");
			frm.admin_password.focus();
			return;
		}		
	}
	frm.submit();
}

//-- Do login admin
function doLoginAdmin(){
	var frm = document.frmLogin;
	frm.submit();
}

//-- Default image functions
function doUpdateDefaultImage(type){
	var f = document.frmDefaultImage;
	if(confirm('Are you sure you want to update default images?')==true){
		f.type.value = type;
		f.submit();
	}
}
function doGetBackDefaultImage(type){
	var f = document.frmDefaultImage;
	if(confirm('Are you sure you want to get back the default images?')==true){
		f.type.value = type;
		f.submit();
	}
}
//select a/////
function onsl(a)
{
	a.value = 1;
}
function onReload()
{
	document.frmquestion.submit();
}
function question_search()
{
	document.frmquestion.submit();
}

//--Style Sheet
function doSaveCSS(){
	var frm = document.frmSaveCSS;
	if(frm.content.value == ''){
		alert("Please input the content!");
		frm.content.focus();
		return;
	}
	frm.submit();
}
function doGetBackDefaultCSS(type){
	var f = document.frmSaveCSS;
	if(confirm('Are you sure you want to get back the default CSS?')==true){
		f.type.value = type;
		f.submit();
	}
}

//-- Do Save Left Menu Content
function doSaveLeftMenuPage(){
	var frm = document.frmLeftContent;
	frm.submit();
}

